package com.sc.auction.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sc.auction.common.jwt.JwtInfo;
import com.sc.auction.common.jwt.JwtUtils;
import com.sc.auction.user.pojo.User;
import com.sc.auction.user.mapper.UserMapper;
import com.sc.auction.user.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.auction.user.vo.UserQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author theTi
 * @since 2020-09-01
 */
@Service
@Transactional
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Override
    public String login(UserQuery user) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username",user.getUsername());
        queryWrapper.eq("password",user.getPassword());
        User result=baseMapper.selectOne(queryWrapper);
        if(result!=null){
            JwtInfo jwtInfo = new JwtInfo();
            jwtInfo.setUserCode(result.getUsername());
            jwtInfo.setId(result.getId());
            String  token= JwtUtils.genJwt(jwtInfo);
            return token;
        }
        return null;
    }
}
